/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package taganalysistoolsclient;

import elaborate.tag_analysis.model.TURRelation;
import elaborate.tag_analysis.restws.client.TURRelationDao;
import java.util.List;
import java.util.UUID;

/**
 *
 * @author lendle
 */
public class TagAnalysisToolsClient4 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        // TODO code application logic here
        TURRelationDao dao=new TURRelationDao("http://taganalysis.appspot.com/rest/tur");
        TURRelation tur=new TURRelation();
        tur.setApplicationId("1");
        tur.setId(UUID.randomUUID().toString());
        tur.setResourceId("1");
        tur.setTagId("1");
        dao.newTURRelation(new TURRelation[]{tur});
        tur.setUserId("hahaha");
        dao.updateTURRelation(tur);
        dao.deleteTURRelation("1", tur.getId());
        List<TURRelation> list=dao.findAll("1");
        System.out.println(list.size());
        tur=dao.findById("1", "3fd9ac8e-7f70-4832-9773-cfb99cb3357a");
        System.out.println(tur);
//        ClientConfig config = new DefaultClientConfig();
//        Client client = Client.create(config);
//        WebResource service = client.resource("http://taganalysis.appspot.com");
//        Form form = new Form();
//        form.add("id", ""+UUID.randomUUID().toString());
//        form.add("resourceId", "test1");
//        form.add("userId", "test1");
//        form.add("tagId", "test1");
//        form.add("applicationId", "1");
//        ClientResponse response = service.path("rest").path("tur").accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, form);
//        TURRelation tur=response.getEntity(TURRelation.class);
//       
//        
//        service.path("rest").path("tur").path("1").path(URLEncoder.encode(""+tur.getId(), "utf-8")).delete();
//        response= service.path("rest").path("tur").path("1").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
//        TURRelation [] turs=response.getEntity(TURRelation[].class);
//        System.out.println(turs.length);
//        response= service.path("rest").path("tur").path("1").path("3fd9ac8e-7f70-4832-9773-cfb99cb3357a").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
//        System.out.println(response.getEntity(TURRelation.class).getId());
    }
}
